/*
 * @Date: 2023-12-18 17:56:34
 * @LastEditors: 玄绮 shijiahansi@qq.com
 * @LastEditTime: 2024-04-13 13:31:40
 * @FilePath: \server\src\server\app\ChatSessionManager.h
 */
#ifndef CHATSESSIONMANAGER_H
#define CHATSESSIONMANAGER_H

#include <boost/smart_ptr/enable_shared_from_this.hpp>
#include <queue>
#pragma once
#include "ChatSession.h"

#include <boost/signals2.hpp>
// #include <data/Account.h>
// #include <packet/message/MessageQueue.hpp>
#include <data/UserInfo.pb.h>
#include <data/Message.pb.h>
#include <map>
#include <string>

using namespace boost::signals2;

class ChatSessionManager:public boost::enable_shared_from_this<ChatSessionManager> {
public:
    using SharedPtr = boost::shared_ptr<ChatSessionManager>;
    using MessageQueue = std::queue<data::Message>;
    ChatSessionManager();
    ~ChatSessionManager();

    typedef boost::signals2::signal<void(std::string, ChatSession::SharedPtr)> signal_t;

public:
    bool isLogin(std::string userId) const;
    void login(ChatSession::SharedPtr session);
    void unlogin(ChatSession::SharedPtr session);
    void unlogin(std::string userId);

public:
    void sendMessage(data::Message msg);

public:
    ChatSession::SharedPtr getSession(std::string userId);
    MessageQueue&          getMessageQueue(std::string userId);

public:
    signal_t signalUserLogin;
    signal_t signalUserUnLogin;

protected:
    std::map<std::string, ChatSession::SharedPtr> sessions;
    std::map<std::string, MessageQueue>           messageQueues;
};

#endif